<script>
  $(document).ready(function() {
    $("#dtText2").datepicker(
		{
		   onSelect: function(dtText, inst) { 
				if(dtText.length>0){
					eventDate = dtText.split("/");
					newEventDate = eventDate[2]+'-'+eventDate[0]+'-'+eventDate[1];
					var url = "<?php echo $html->url(array('controller'=>'events','plugin'=>'events','action'=>'browse'))?>";		
					url += '/ByTime:'+newEventDate;
					window.location = url;
				}
		   }
		}
	);
  });
</script>
<section class="hauptseite deals">
	<div class="container">
		<div class="row">
			<h2>Events</h2>
			<?php
			//	<h2>Popular events this week</h2>
			if($beingReloaded==0)
			{
				if(isset($showAddButton) && ($showAddButton))
				{
					echo $html->link('<span>'.__('Add an Event').'</span>', array('controller'=>'events','plugin'=>'events','action'=>'add'),array('class'=>'button float_r','escape'=>false));
				}
			}
			?>
			<div class="wrap_events">
				<div class="col-md-6 event_popular Left_event">
					<?php
					if (!$beingReloaded) 
					{
						/*$reqData = $this->requestAction('events/populartw');
						$listEvents = $reqData[0];
						$view_type2 = $reqData[1];*/
					
						App::import('Model','Events.Event');
						$tempEvent = new Event();
						$listEvents = $tempEvent->getPopularThisWeek(4);
						if (!isset($view_type))
						{
							$view_type = "blog_view";
						}
					?>
					<?php echo "<h2 class='module_title'>".__("Popular events this week")."</h2>";?>
					<div class="event_week">
						<div class="blog_view">
							<?php 
							if(!empty($listEvents))
							{?>
							<div id="popular_ineventsindex"> <?php echo $this->element('events', array('eventList' => $listEvents,'eventCallerName'=>'populartw2','view_type'=>$view_type,'loggedInUserId'=>$loggedInUserId));?> </div>
							<!--<div class="event box_in">
								<div align="center" class="image"> <a href="events_detail.php" title="White Truffle Series"> <img src="images/event_img.jpg" alt="White Truffle Series" title="White Truffle Series"> </a> </div>
								<div class="info_review">
									<div class="other_info"> <a class="event_name" href="events_detail.php">White Truffle Series</a>
										<div class="event_info"> <a href="#" title="Food">Food</a> <br>
											Saturday, November, 08 08:41 <br>
											Thursday, November, 24 21:00<br>
										</div>
										<div class="intrested fl">4 are interested !</div>
									</div>
								</div>
								<div class="clear"></div>
							</div>-->
							<?php 
							}
							else
							{
								echo __('No events found!');
							}
							?>
						</div>
						<!--/.blog_view--> 
					</div>
					<!-- event_week-->
					<?php }?>
				</div>
				<!--Left_event-->
				
				<div class="col-md-6 event_popular right_event">
					<?php
					if($beingReloaded==0){
						$listEvents2 = $tempEvent->getOtherPopularEvents(10);
						echo "<h2 class='module_title'>".__('Other popular events')."</h2>";
						?>
					<div class="event_all">
						<?php 
						if(!empty($listEvents2)){
						?>
						<div class="top_events_all"> <span><?php echo __("See Events For").":";?></span>
							<?php echo "<input type='label' value='".__("Jump to date")."' readonly='true' name = 'dtText2' id='dtText2' onClick='$(this).datepicker().datepicker( \"show\" );' size='12' class='ip_Date hasDatepicker' />";?>
							<?php echo $html->link(__('Browse all events'), array('controller'=>'events','plugin'=>'events','action'=>'browse'),array('class'=>'button'));?>
							<ul class="filters_events">
								<li><?php echo $html->link(__('Today', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Today'));?></li>
								<li><?php echo $html->link(__('Tomorrow', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Tomorrow'));?></li>
								<li><?php echo $html->link(__('This Weekend', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'This_Weekend'));?></li>
								<li><?php echo $html->link(__('This Week', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'This_Week'));?></li>
								<li><?php echo $html->link(__('Next Week', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Next_Week'));?></li>
							</ul>
						</div>
						
						<!--/.top_events_all-->
						<?php echo $this->element('events', array('eventList' => $listEvents2,'eventCallerName'=>'otherpopular2','view_type'=>$view_type,'loggedInUserId'=>$loggedInUserId));?>
						<!--<div class="event box_in">
							<div align="center" class="image"> <a href="events_detail.php" title="Nutcracker Craft Boutique"> <img src="images/event_img.jpg" alt="Nutcracker Craft Boutique " height="100" width="100" title="Nutcracker Craft Boutique "> </a> </div>
							<div class="info_review">
								<div class="other_info"> <a class="event_name" href="events_detail.php">Nutcracker Craft Boutique </a>
									<div class="event_info"> <span class="label_ev">From:</span> <span class="time_vl">Wednesday, June, 08 09:00 <br>
										Monday, August, 07 20:00</span> <span class="label_ev">Category:</span>&nbsp; <a href="#" title=" Festivals &amp;amp; Fairs"> Festivals &amp; Fairs </a>
										<div class="event_venue"> <span class="label_ev">Venue:</span>333 Hayes St, San Francisco, 5 </div>
									</div>
									<div class="description">Shop from over 250 vendors that display one-of-a-kind, hand-crafted holiday gifts, decorations, food, and collectibles. Shoppers can also pick up a quick...</div>
									<div class="intrested fl"> </div>
									<div class="fr  submit_by">Submitted By: <a href="#" class="poster" title="steven's profile">steven</a></div>
								</div>
							</div>
						</div>-->
						<?php } else {
							echo __('No events found!');
						}?>
						
					</div>
					<!--event_all-->
					<?php }?>
				</div>
				<!-- /.right_event --> 
			</div>
			<!--/.wrap_events--> 
			
		</div>
		<!--/.row--> 
	</div>
	<!--/.container--> 
</section>
<!-- /.hauptseite-->
<script>
	function getCatEVents()
	{
		newCatId = document.getElementById('category').value;
		newDate = document.getElementById('dtText').value;
		newEventDate = '';
		if(newDate.length>0){
			eventDate = newDate.split("/");
			newEventDate = eventDate[2]+eventDate[0]+eventDate[1];
		}
		var url = "<?php echo $html->url(array('action'=>'index'))?>";		
		url += '/categoryId:'+newCatId+'/eventDate:'+newEventDate;
		$('#events_index').html('<img src="'+AJAX_LOADING_IMG+'"/>');
		$.get(url,function(html){ 
			$('#events_index').html(html);
		});
	}
</script>
<?php return;?>
<script>
  $(document).ready(function() {
    $("#dtText2").datepicker(
		{
		   onSelect: function(dtText, inst) { 
				if(dtText.length>0){
					eventDate = dtText.split("/");
					newEventDate = eventDate[2]+'-'+eventDate[0]+'-'+eventDate[1];
					var url = "<?php echo $html->url(array('controller'=>'events','plugin'=>'events','action'=>'browse'))?>";		
					url += '/ByTime:'+newEventDate;
					window.location = url;
				}
		   }
		}
	);
  });
</script>
<?php $html->css('/events/css/events.css',null,array(),false);?>
<h2 class="fl">Events</h2>
<?php
//	<h2>Popular events this week</h2>
if($beingReloaded==0)
{
	if(isset($showAddButton) && ($showAddButton))
	{
		echo $html->link('<span>'.__('Add an Event').'</span>', array('controller'=>'events','plugin'=>'events','action'=>'add'),array('class'=>'button float_r','escape'=>false));
	}
}
?>
<div class="clear"></div>
<div class="noborder">
	<div id="event_indexpopularblock">
		<?php
	if (!$beingReloaded) 
	{
		/*$reqData = $this->requestAction('events/populartw');
		$listEvents = $reqData[0];
		$view_type2 = $reqData[1];*/
	
		App::import('Model','Events.Event');
		$tempEvent = new Event();
		$listEvents = $tempEvent->getPopularThisWeek(4);
		if (!isset($view_type))
		{
			$view_type = "blog_view";
		}
		echo "<h2 class='module_title'>".__("Popular events this week")."</h2>";
		if(!empty($listEvents))
		{?>
		<div id="popular_ineventsindex"> <?php echo $this->element('events', array('eventList' => $listEvents,'eventCallerName'=>'populartw2','view_type'=>$view_type,'loggedInUserId'=>$loggedInUserId));?> </div>
		<?php 
		}
		else
		{
			echo "<div class='no_results'>".__('No events found!')."</div>";
		}
	}
	?>
		<div class="clear"></div>
	</div>
	<div class="clear"></div>
	<hr>
	<div id="event_block">
		<div>
			<?php
if($beingReloaded==0){

	$listEvents2 = $tempEvent->getOtherPopularEvents(10);

	echo "<h2 class='module_title'>".__('Other popular events')."</h2>";
		echo $html->link(__('Browse all events'), array('controller'=>'events','plugin'=>'events','action'=>'browse'),array('class'=>'button'));

if(!empty($listEvents2))
	{
		echo "<ul class='filters_events'>";
		echo "<li>";
		echo __("See Events For").":";
		echo "</li><li>";
		echo $html->link(__('Today', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Today'));
		echo "</li><li>";
		echo $html->link(__('Tomorrow', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Tomorrow'));
		echo "</li><li>";
		echo $html->link(__('This Weekend', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'This_Weekend'));
		echo "</li><li>";
		echo $html->link(__('This Week', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'This_Week'));
		echo "</li><li>";
		echo $html->link(__('Next Week', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Next_Week'));
		echo "</li><li class='last'>";
		echo "<input type='label' value='".__("Jump to date")."' readonly='true' name = 'dtText2' id='dtText2'  onClick='$(this).datepicker().datepicker( \"show\" );' size='12' />";
		echo "</li></ul>"; ?>
			<hr>
			<div id="popular_ineventsindex2"> <?php echo $this->element('events', array('eventList' => $listEvents2,'eventCallerName'=>'otherpopular2','view_type'=>$view_type,'loggedInUserId'=>$loggedInUserId));?> </div>
			<div class="clear"></div>
			<?php 
	}
	else
	{
		echo "<div class='no_results'>".__('No events found!')."</div>";
	}
}
?>
		</div>
		<div class="clear"></div>
		<?php
//unset is neccesary
unset($paginator->Html);
$paginator->Html = $appHtml;
?>
		<?php
//$paginator->options(array('url'=>$this->getPagingUrl()));
	if($beingReloaded)
	{
		if(!empty($events))
		{?>
		<div class="user_actions">&nbsp;&nbsp; <span> <strong><?php echo __("Sort By")?> :</strong></span> <span><?php echo $paginator->sort(__('Recently added'),'created',array('url'=>array('direction'=>'desc')));?> | </span> <span><?php echo $paginator->sort(__('Title'),'Event.title',array('url'=>array('direction'=>'both')));?> | </span> <span><?php echo $paginator->sort(__('Free'),'Event.event_cost_to',array('url'=>array('direction'=>'asc')));?> | </span> <span><?php echo $paginator->sort(__('Most Viewed'),'Event.view_count',array('url'=>array('direction'=>'desc')));?> | </span> <span><?php echo $paginator->sort(__('Popular Events'),'(Event.soundscool_count+Event.whosin_count)',array('url'=>array('direction'=>'desc')));?></span> </div>
		<br/>
		<!--
			<div class="user_actions">&nbsp;&nbsp;
				<?php //echo $this->element('event_sort_filter'); ?>
			</div><br/>
			-->
		<div id="eventsindex"> <?php echo $this->element('events', array('eventList' => $events,'view_type'=>$view_type,'loggedInUserId'=>$loggedInUserId,'eventCallerName'=>'catwiseeventsresult'));?> </div>
		<div class='paginate'> <?php echo $paginator->prev(__('Prev'));?> <?php echo $paginator->numbers(array('separator'=>' '));?> <?php echo $paginator->next(__('Next'));?> </div>
		<div class="clear"></div>
		<?php 
		}
		else
		{
			echo "<div class='no_results'>".__('No events found!')."</div>";
		}
	}
	?>
	</div>
	<div class="clear"></div>
	<?php 
		if ($beingReloaded == 0) {
			$events  = am($listEvents,$listEvents2);
		}
		if (!empty($events)) { 
		?>
	<div class="listing-view-map">
		<?php 
				//@GEOMAP INTERSECTION.
				//echo $this->element("event_view_map",array('showStreetView'=>true,'events'=>$events));?>
	</div>
	<?php } ?>
</div>
<script>
	function getCatEVents()
	{
		newCatId = document.getElementById('category').value;
		newDate = document.getElementById('dtText').value;
		newEventDate = '';
		if(newDate.length>0){
			eventDate = newDate.split("/");
			newEventDate = eventDate[2]+eventDate[0]+eventDate[1];
		}
		var url = "<?php echo $html->url(array('action'=>'index'))?>";		
		url += '/categoryId:'+newCatId+'/eventDate:'+newEventDate;
		$('#events_index').html('<img src="'+AJAX_LOADING_IMG+'"/>');
		$.get(url,function(html){ 
			$('#events_index').html(html);
		});
	}
</script> 
